use log::info;
use tokio::net::TcpStream;

use crate::{cli::Cli, error::Error};

//create_topic --topic test --replication-factor 2 --partitions 3
pub async fn create_topic(stream: TcpStream, cli: &Cli) -> Result<(), Error> {
    let command = format!(
        "{} --topic {} --partitions {} --replication-factor {}\n",
        cli.command, cli.topic, cli.partitions, cli.replication_factor
    );
    match stream.try_write(command.as_bytes()) {
        Ok(_) => {
            info!("command: {command}");
        }
        Err(e) => {
            return Err(e.into());
        }
    }
    Ok(())
}
